Skip to content

Conversation

@7amed3li
Copy link

This PR adds lightweight stats tracking for pacote.extract by injecting a tracked extract function.
This helps identify slow package extractions and potential bottlenecks during scans.

No breaking changes - existing code works as-is.

Closes #615

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: e985c9f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@nodesecure/tarball Minor
@nodesecure/scanner Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@clemgbld clemgbld requested a review from fraxken January 30, 2026 00:10
spec,
registry
registry,
extractFn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would just inline the operation and rename the extractFn to pacoteProvider:

{
pacoteProvider:(spec: string, dest: string, opts: pacote.Options) => statsCollector.track(
          `pacote.extract ${spec}`,
          () => pacote.extract(spec, dest, opts)
        )
}

};
}

type ExtractFunction = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rename it PacoteProvider and use an interface with the method extract

ref: any;
statsCollector: StatsCollector;
extractFn?: (spec: string, dest: string, opts: pacote.Options) => Promise<void>;
pacoteProvider?: import("@nodesecure/tarball").PacoteProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s more readable to import the type at the top of the file

pacoteProvider: {
extract: async(spec: string, dest: string, opts: pacote.Options) => {
await statsCollector.track(
`pacote.extract[${spec}]`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pacote.extract[${spec}] -> pacote.extract ${spec}

It’s the same pattern in the two other examples

registry,
statsCollector,
extractFn: trackedExtract
pacoteProvider: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just build the the object once and reuse the same, and not building a new one for each scan

@7amed3li 7amed3li force-pushed the feat/stats-tracking-pacote-extract branch from 02daaed to 3483f28 Compare January 30, 2026 13:00

const pacoteProvider: PacoteProvider = {
extract: async(spec, dest, opts) => {
await statsCollector.track(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t need the async await syntax since you don’t need the awaited result in this function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add stats tracking on pacote.extract through extractAndResolve

2 participants